package com.amigo.online.provider.adv.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.amigo.online.provider.adv.entity.AdvRecommendLookRecord;
import com.amigo.online.provider.adv.mapper.AdvRecommendLookRecordMapper;
import com.amigo.online.provider.adv.service.AdvRecommendLookRecordService;
import com.amigo.online.provider.adv.service.AdvRecommendStockService;

@Service
public class AdvRecommendLookRecordServiceImpl implements AdvRecommendLookRecordService {

    @Autowired
    AdvRecommendLookRecordMapper advRecommendLookRecordMapper;

    @Autowired
    AdvRecommendStockService advRecommendStockService;

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void recordHomeAdvLooked(Long advId, String device, Long userId) {
        AdvRecommendLookRecord record = new AdvRecommendLookRecord(advId, userId, device);
        //记录数据
        advRecommendLookRecordMapper.insert(record);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void recordRecommendAdvLooked(long advId, String sex, Long age, Double lng, Double lat, String city) {
        AdvRecommendLookRecord record = new AdvRecommendLookRecord(advId, sex, age, lng, lat, city);
        advRecommendLookRecordMapper.insert(record);
        advRecommendStockService.deductionRecommendAdvLookStock(advId);
    }


}
